import { createRouter, createWebHistory } from 'vue-router'
import AnomalyDetectionView from '../views/AnomalyDetection.vue'
import DashboardView from '../views/DashboardView.vue'
import SmartAssistantView from '../views/SmartAssistantView.vue'
import KnowledgeGraphView from '../views/KnowledgeGraphView.vue'
import FaultInfoView from '../views/FaultInfoView.vue'
import FaultTracingView from '../views/FaultTracingViewTest.vue'
import HomePage from '../views/HomePage.vue'
import FaultTracing from '../views/FaultTracing.vue'
import CustomChartView from '../views/CustomChartView.vue'
// 您可能需要创建其他视图组件，例如：
// import RealtimeMonitoringView from '../views/RealtimeMonitoringView.vue';
// import RiskWarningView from '../views/RiskWarningView.vue';
// import OperationHandlingView from '../views/OperationHandlingView.vue';

const routes = [
  // {
  //   path: '/',
  //   name: 'Home',
  //   component: HomePage,
  //   meta: { title: '首页' },
  // },
  {
    path: '/',
    redirect: '/dashboard', // 默认重定向到仪表盘
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: DashboardView,
    meta: { title: '智能运维 - 仪表盘' },
  },
  {
    path: '/anomaly-detection',
    name: 'AnomalyDetection',
    component: AnomalyDetectionView,
    props: (route) => ({ deviceName: route.query.deviceName }),
    meta: { title: '全流程检测与诊断' },
  },
  {
    path: '/smart-assistant', // 新页面的路径
    name: 'SmartAssistant',
    component: SmartAssistantView, // 对应的组件
    meta: { title: '智能助手' },
  },
  {
    path: '/knowledge-graph', // 新页面的路径
    name: 'KnowledgeGraph',
    component: KnowledgeGraphView, // 对应的组件
    meta: { title: '设备运维知识图谱' },
  },
  {
    path: '/fault-info', // 新页面的路径
    name: 'FaultInfo',
    component: FaultInfoView, // 对应的组件
    meta: { title: '故障信息' },
  },
  {
    path: '/fault-tracing/:sensorId/:alarmId', // 新增故障溯源页面路径
    name: 'FaultTracing',
    component: FaultTracing, // 对应的组件
    //redirect: '/fault-tracing/FIC1001/alarm_FIC1001_1752913124903',
    meta: { title: '故障溯源' },
  },
  {
    path: '/custom-chart', // 新增自定义图表页面的路径
    name: 'CustomChart',
    component: CustomChartView, // 对应的组件
    meta: { title: '自定义查询' },
  },
]

const router = createRouter({
  history: createWebHistory(), // 使用 HTML5 History 模式
  routes,
})

// 可选：全局前置守卫，用于修改页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = '智能运维平台' // 默认标题
  }
  next()
})

export default router
